package logic

import (
	"context"
	"taobao/models/mysql"

	"taobao/taobaorpc/internal/svc"
	"taobao/taobaorpc/taobaorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopAddLogic {
	return &ShopAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopAddLogic) ShopAdd(in *taobaorpc.ShopAddRequest) (*taobaorpc.ShopAddResponse, error) {
	// todo: add your logic here and delete this line
	shop := mysql.Shop{
		Title:  in.Title,
		Price:  in.Price,
		Image:  in.Image,
		UserId: int(in.UserId),
	}
	mysql.DB.Debug().Create(&shop)
	return &taobaorpc.ShopAddResponse{
		ShopId: int64(shop.ID),
	}, nil
}
